exports.install = function (Vue, options) {

    Vue.prototype.post = function (url, obj, callBack) {
        if (typeof (obj) == "function") {
            callBack = obj;
            obj = "";
        }
        let that = this;

        this.openLoading(function (index) {
            that.$axios({
                method: "POST",
                url: url,
                data: obj,
                ContentType: 'application/json',
            }).then((response) => {
                that.closeLoading();
                setTimeout(() => {
                    callBack(response.data);
                }, 10);
            }).catch(function (error) {
                console.log(error);
                that.closeLoading();
                that.showMsg('post请求失败', false);
            })
        });
    }
    Vue.prototype.get = function (url, obj, callBack) {
        if (typeof (obj) == "function") {
            callBack = obj;
            obj = "";
        }
        this.openLoading(function (index) {
            this.$axios.get(url, {
                params: obj,
            }).then((response) => {
                that.closeLoading();
                setTimeout(() => {
                    callBack(response.data);
                }, 10);
            }).catch(function (error) {
                that.closeLoading();
                that.showMsg('get请求失败', false);
            })
        });
    }
    Vue.prototype.getRsaData = function (str) {
        var pubKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbdT3CpI6tPlKAXU2+Lm3VDSWCd9/ZDzQZa7fd\n' +
            'QAi6TEMt5r5TVrvaHfTgU3xNElI2Nfc9z5qX6FB77ZU+vP0CAfo4A6LoVuW4uV9a6sBeSevGdRtc\n' +
            'kwQNuHvQw43tyWp2TwXfeATD1FNHtbQWUKdhwoEtJBbigb10ISgGxIJJWQIDAQAB';
        let encryptStr = new JSEncrypt();
        encryptStr.setPublicKey(pubKey); // 设置 加密公钥
        let data = encryptStr.encrypt(str.toString()); // 进行加密
        return data;
    }

    Vue.prototype.getCheckBoxValues = function (name, isChecked) {
        var data = [];
        if (typeof (isChecked) != "boolean") {
            $("input:checkbox[name='" + name + "']").each(function () { // 遍历name=standard的多选框
                data.push(this.value);
            });
            return data.join(",");
        }
        if (isChecked) {
            $("input:checkbox[name='" + name + "']:checked").each(function () { // 遍历name=standard的多选框
                data.push(this.value);
            });
            return data.join(",");
        } else {
            $("input:checkbox[name='" + name + "']:not(:checked)").each(function () { // 遍历name=standard的多选框
                data.push(this.value);
            });
            return data.join(",");
        }
    }

    Vue.prototype.checkIsNull = function (str) {
        if (str == null || str == "" || typeof (str) == "undefined" || str == "null" || str == "undefined") {
            return true;
        } else {
            return false;
        }
    }

    Vue.prototype.checkPhone = function (phone) {
        var res = /[1]{1}[0-9]{10}/;
        var re = new RegExp(res);
        if (re.test(phone)) {
            return true;
        } else {
            return false;
        }
    }

    Vue.prototype.checkNumber = function (val) {
        // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
        if (val === "" || val == null) {
            return false;
        }
        if (!isNaN(val)) {
            //对于空数组和只有一个数值成员的数组或全是数字组成的字符串，isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
            //所以如果不需要val包含这些特殊情况，则这个判断改写为if(!isNaN(val) && typeof val === 'number' )
            return true;
        } else {
            return false;
        }
    }

    Vue.prototype.getUUID = function () {
        var d = new Date().getTime();
        if (window.performance && typeof window.performance.now === "function") {
            d += performance.now(); //use high-precision timer if available
        }
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
        return uuid;
    }

    Vue.prototype.getID = function () {
        var res = /^[a-zA-Z]{1}[0-9]+[a-zA-Z]+$/
        var id = "_"+Number(Math.random().toString().substr(3, 30) + Date.now()).toString(36);
        // var r = id.match(res);
        // if (r == null) {
        //     return this.getID();
        // }
        
        return id;
    }

    Vue.prototype.parseDom = function (htmlText) {
        console.log(htmlText);
        var div = document.createElement("div");

        div.innerHTML = htmlText;
        return div.childNodes[0];
    }
}